
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        1/9/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteProductBUL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using MCWEBSITE.DAL;
using MCWEBSITE.ENTITY;
using System.Data;

namespace MCWEBSITE.BUL
{
    public class websiteProductBUL
    {
        public static int Save(websiteProductInfo _websiteProductInfo)
        {
            try
            {
                if (_websiteProductInfo.ItemID == 0)
                {
                    return websiteProductDAL.Insert(_websiteProductInfo);
                }
                else
                {
                    return websiteProductDAL.Update(_websiteProductInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error on insert theme : {0}", ex.Message));
            }
        }

        public static int publish(int ID)
        {
            try
            {
                return websiteProductDAL.publish(ID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error on insert theme : {0}", ex.Message));
            }
        }

        public static int unpublish(int ID)
        {
            try
            {
                return websiteProductDAL.unpublish(ID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error on insert theme : {0}", ex.Message));
            }
        }

        public static int Remove(int _ItemID)
        {
            try
            {
                return websiteProductDAL.Delete(_ItemID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error on delete Theme : {0}", ex.Message));
            }
        }

        public static List<websiteProductInfo> GetAll()
        {
            try
            {
                return websiteProductDAL.SelectAll();
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }
        
        public static List<websiteProductInfo> GetByLanguage(string status, string LanguageCode)
        {
            try
            {
                return websiteProductDAL.SelectByLanguage(status, LanguageCode);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static DataSet GetByLanguageDS(string status, string LanguageCode)
        {
            try
            {
                return websiteProductDAL.SelectByLanguageDS(status, LanguageCode);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteProductInfo> GetByLanguageAndCategoryDS(int CatId, string status, string LanguageCode)
        {
            try
            {
                return websiteProductDAL.GetByLanguageAndCategoryDS(CatId, status, LanguageCode);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteProductInfo> GetByLanguageAndTypeDS(int TypeID, string status, string LanguageCode)
        {
            try
            {
                return websiteProductDAL.GetByLanguageAndTypeDS(TypeID, status, LanguageCode);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static DataSet GetDetails(int ID)
        {
            try
            {
                return websiteProductDAL.GetDetails(ID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteProductInfo> SelectNtoMByLanguage(int N, int M, string status, string LanguageCode)
        {
            try
            {
                return websiteProductDAL.SelectNtoMByLanguage(N, M, status, LanguageCode);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteProductInfo> SelectNtoMByLanguageAndCat(int N, int M, string status, string LanguageCode, int CatId)
        {
            try
            {
                return websiteProductDAL.SelectNtoMByLanguageAndCat(N, M, status, LanguageCode, CatId);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteProductInfo> GetByStatus(string status)
        {
            try
            {
                return websiteProductDAL.GetByStatus(status);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static websiteProductInfo Load(int _ItemID)
        {
            try
            {
                return websiteProductDAL.SelectOne(_ItemID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteProductInfo> Search()
        {
            try
            {
                return websiteProductDAL.SelectFilters();
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static int InsertResource(int NewsId, string Resources)
        {
            try
            {
                return websiteProductDAL.InsertResource(NewsId, Resources);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        //lay tat ca cac san pham theo category va category con cua no
        public static List<websiteProductInfo> GetByLanguageAndCategory(int CatId, string status, string LanguageCode) { 
            try
            {
                return websiteProductDAL.GetByLanguageAndCategory(CatId, status, LanguageCode);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }
    }
}

